package gd.qaq.blue.bluespick.api;

import gd.qaq.blue.bluespick.BluesPick;
import gd.qaq.blue.bluespick.dto.AreaData;
import gd.qaq.blue.bluespick.dto.PickBlockData;
import org.bukkit.Location;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;

public class PickAPI {
    /**
     * 检测玩家是否在某个区域
     */
    public static AreaData checkInArea(Player player) {
        Location location = player.getLocation();
        for (AreaData area : BluesPick.areas) {
            if (area.getArea().contain(location)) {
                return area;
            }
        }
        return null;
    }

    /**
     * 检测方块是否在存在某区域
     */
    public static AreaData checkInArea(Block block) {
        Location location = block.getLocation();
        for (AreaData area : BluesPick.areas) {
            if (area.getArea().contain(location)) {
                return area;
            }
        }
        return null;
    }

    /**
     * 判断是否是可采集物
     */
    public static PickBlockData isPickBlock(Block block) {
        //没有全息图的也算作非采集物
//        if(BluesPick.holograms.size()!=0&&BluesPick.holograms.get(block.getTypeId()+":"+block.getData()+"&&"+block.getLocation().getWorld().getName()+"&&"+
//                block.getLocation().getX()+"&&"+block.getLocation().getY()+"&&"+block.getLocation().getZ())==null){
//            return null;
//        }
        //获取到区域数据
        AreaData data = checkInArea(block);
        if(data==null) return null;
        //拿到区域名和方块id到数据库中查找，如果有结果说明就是可采集物
        PickBlockData pick = BluesPick.jdbcUtils.getPick(block,data, block.getTypeId() + ":" + block.getData());
        if(pick!=null){
            return pick;
        }
        return null;
    }
}
